<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品信息列表')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>所属商户：</p>
                            <select id="merchantId" class="form-control" name="merchantId">
                                <option value="">------全部------</option>
                                <option th:each="post:${mts}"
                                        th:value="${post.merchantId}"
                                        th:text="${post.merchantName}"></option>
                            </select>
                        </li>
                        <li>
                            <p>产品名称：</p>
                            <input type="text" name="commodityName"/>
                        </li>
                        <li>
                            <p>商品属性：</p>
                            <select name="commodityAttribute" th:with="type=${@dict.getType('t_merchant_attribute')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <p>商品状态：</p>
                            <select name="commodityStatus" th:with="type=${@dict.getType('t_merchant_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <p>商品类型：</p>
                            <select name="commodityType" th:with="type=${@dict.getType('t_commodity_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <p>商品类别：</p>
                            <div class="input-group" style="width: 200px;">
                                <input id="treeId" name="categoryId" type="hidden"
                                       th:value="${commodityCategory?.categoryId}"/>
                                <input placeholder="点击选择类别" class="form-control" type="text"
                                       onclick="selectCommoditycategoryTree()"
                                       id="treeName"
                                       readonly="true" th:value="${commodityCategory?.categoryName}" required>
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </li>
                        <li>
                            <p>审核状态：</p>
                            <select name="examineStatus" th:with="type=${@dict.getType('t_comm_examine_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset(null,'merchantId')"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="bussiness:commodityinfo:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.editFull()"
               shiro:hasPermission="bussiness:commodityinfo:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="bussiness:commodityinfo:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="bussiness:commodityinfo:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('bussiness:commodityinfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('bussiness:commodityinfo:remove')}]];
    var examineFlag = [[${@permission.hasPermi('bussiness:commodityinfo:examine')}]];
    var commodityAttributeDatas = [[${@dict.getType('t_merchant_attribute')}]];
    var commodityStatusDatas = [[${@dict.getType('t_merchant_status')}]];
    var examineStatusDatas = [[${@dict.getType('t_comm_examine_status')}]];
    var commodityTypeDatas = [[${@dict.getType('t_commodity_type')}]];
    var prefix = ctx + "bussiness/commodityinfo";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "产品信息",
            sortName: "zebraOrder asc,createTime",
            sortOrder: "desc",
            columns: [{
                checkbox: true
            },
                {
                    field: 'commodityId',
                    title: '产品id',
                    visible: false
                },
                {
                    field: 'merchantName',
                    title: '所属商户'
                },
                {
                    field: 'commodityName',
                    title: '产品名称'
                },
                {
                    field: 'commodityBrief',
                    title: '产品简介'
                },
                {
                    field: 'commodityIntroduce',
                    title: '产品详情',
                    visible: false
                },
                {
                    field: 'commodityMoeny',
                    title: '商品费用(元)', formatter: function (value) {
                        if (value == 0)
                            return '免费';
                        return (value / 100).toFixed(2);
                    }
                },
                {
                    field: 'commodityType',
                    title: '商品类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(commodityTypeDatas, value);
                    }
                },
                {
                    field: 'commodityFreight',
                    title: '商品运费(元)', formatter: function (value) {
                        if (value == 0)
                            return '免费';
                        return (value / 100).toFixed(2);
                    }
                },
                {
                    field: 'commodityImg',
                    title: '产品图片',
                    formatter: function (value) {
                        if (value) {
                            value = ctx + "profile" + value;
                            return "<img src='"
                                + value
                                + "' style='height: 36px;' target='_blank' tile='点击查看' onclick='$.operate.alertPic(\""
                                + value
                                + "\")'></img>";
                        }
                    }
                },
                {
                    field: 'commodityAttribute',
                    title: '商品属性',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(commodityAttributeDatas, value);
                    }
                },
                {
                    field: 'commodityStatus',
                    title: '商品状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(commodityStatusDatas, value);
                    }
                },
                {
                    field: 'categoryName',
                    title: '商品类别'
                },
                {
                    field: 'examineStatus',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(examineStatusDatas, value);
                    }
                },
                {
                    field: 'examineDesc',
                    title: '审核描述',
                    visible: false
                },
                {
                    field: 'commodityCount',
                    title: '库存总量'
                },
                {
                    field: 'zebraOrder',
                    title: '排序'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true,
                },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    sortable: true,
                },
                {
                    field: 'updateBy',
                    title: '操作人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs ' + examineFlag + '" href="javascript:void(0)" onclick="examine(\'' + row.commodityId + '\')"><i class="fa fa-credit-card"></i>审核</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.commodityId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.commodityId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*产品类别-新增-选择父部门树*/
    function selectCommoditycategoryTree() {
        var options = {
            title: '产品类别选择',
            width: "380",
            url: ctx + "bussiness/commoditycategory/selectCommoditycategoryTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree, true)) {
            var body = layer.getChildFrame('body', index);
            var goodId = body.find('#treeId').val();
            $("#treeId").val(goodId);
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }

    function examine(commodityId) {
        $.modal.open("审核产品信息", prefix + "/examine/" + commodityId);
    }
</script>
</body>
</html>